package com.hongxun.budget.ui.fragment;

import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.activity.LoginActivity;
import com.hongxun.budget.ui.activity.sg.AuxiliaryActivity;
import com.hongxun.budget.ui.activity.sg.myOfflineMapActivity;
import com.hongxun.budget.utils.SgStrKey;
import com.hongxun.entity.LoginInfo;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/7/19.
 */

public class MyFragment extends BaseFragment {
    @BindView(R.id.center_title)
    TextView centerTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.company)
    TextView company;
    @BindView(R.id.phone)
    TextView phone;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    public void initView() {
        centerTitle.setText("我的");
        LoginInfo loginInfo = LoginInfo.getInfo(context);
        name.setText(loginInfo.getUsername());
        company.setText(loginInfo.getDeptName());
        phone.setText(loginInfo.getMobile());
    }


    @OnClick({R.id.clear, R.id.map, R.id.loginOut})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.clear:
                clear2Data();
                break;
            case R.id.map:
                if (Build.VERSION.SDK_INT >= 23) {
                    startActivity(new Intent(getActivity().getApplicationContext(), com.amap.api.maps.offlinemap.OfflineMapActivity.class));
                } else {
                    startActivity(new Intent(getActivity(), myOfflineMapActivity.class));
                }
                break;
            case R.id.loginOut:
                LoginInfo.remove(context);
                startActivity(new Intent(context, LoginActivity.class));
                getActivity().finish();
                break;
        }
    }

    //临时设置：清除材料到位数据、施工进度数据、中间检查数据
    private void clear2Data() {
        startActivity(new Intent(getActivity(), AuxiliaryActivity.class)
                .putExtra("tabName", SgStrKey.clearcache));
    }
}
